/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package towerz.game;

import javax.microedition.lcdui.Image;
import towerz.game.level.Level;
import towerz.system.BitmapFont;
import towerz.system.StringManager;

/**
 *
 * @author LegACy
 */
public class Player {
	public Player(Level data) {
		//Initialize
		m_Wave		= 0;
		m_Level		= data;
		m_Gold		= m_Level.getGold();
		m_Life		= m_Level.getLife();
		int Extra	= m_Wave >= m_Level.getWaveLength() ? 0 : 1;
		
		//Create images
		String Gold	= String.valueOf(m_Gold);
		if (m_Level.getGoldGoal() > 0) Gold += "/" + m_Level.getGoldGoal();
		String Waves = (m_Wave + Extra) + "/" + m_Level.getWaveLength() + " " + StringManager.instance().getString("wave").toLowerCase();
		m_GoldString = BitmapFont.getFont(BitmapFont.MAIN).renderTransparentText(Gold, 0x00000000);
		m_LifeString = BitmapFont.getFont(BitmapFont.MAIN).renderTransparentText(String.valueOf(m_Life), 0x00000000);
		m_WaveString = BitmapFont.getFont(BitmapFont.MAIN).renderTransparentText(Waves, 0x00000000);
	}
	
	public int getWave()			{	return m_Wave;			}
	public int getGold()			{	return m_Gold;			}
	public int getLife()			{	return m_Life;			}
	public Image getLifeString()	{	return m_LifeString;	}
	public Image getGoldString()	{	return m_GoldString;	}
	public Image getWaveString()	{	return m_WaveString;	}
	
	public void nextWave() {
		//Increment wave
		m_Wave++;
		int Extra		= m_Wave >= m_Level.getWaveLength() ? 0 : 1;
		
		//Create string image
		String Waves	= (m_Wave + Extra) + "/" + m_Level.getWaveLength() + " " + StringManager.instance().getString("wave").toLowerCase();
		m_WaveString	= BitmapFont.getFont(BitmapFont.MAIN).renderTransparentText(Waves, 0x00000000);
	}
	
	public void decrementLife() {
		//Reduce life
		m_Life--;
		m_LifeString = BitmapFont.getFont(BitmapFont.MAIN).renderTransparentText(String.valueOf(m_Life), 0x00000000);
	}
	
	public void addGold(int addition) {
		//Skip if 0
		if (addition == 0) return;
		
		//Set gold
		m_Gold += addition;
		String Gold	= String.valueOf(m_Gold);
		if (m_Level.getGoldGoal() > 0) Gold += "/" + m_Level.getGoldGoal();
		m_GoldString = BitmapFont.getFont(BitmapFont.MAIN).renderTransparentText(Gold, 0x00000000);
	} 
	
	//Data
	protected int	m_Gold;
	protected int	m_Life;
	protected int	m_Wave;
	protected Level m_Level;
	
	//String images
	protected Image m_GoldString;
	protected Image m_LifeString;
	protected Image m_WaveString;
}
